package com.playmodule.vr.projections;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

public abstract class Projection {
    public static final int AMBILIGHT_DEPTH = 2048;
    static final int COORDS_PER_QUAD = 6;
    static final int COORDS_PER_UV = 2;
    static final int COORDS_PER_VERTEX = 3;
    public static final int DISTANCE = 65536;
    private static final int FLOAT_SIZE_BYTES = 4;
    public static final int FORMAT_MONO = 0;
    public static final int FORMAT_OVER_UNDER = 2;
    public static final int FORMAT_SIDE_BY_SIDE = 1;
    public static final float RADIUS = 64.0F;
    private static final int SHORT_SIZE_BYTES = 2;
    protected static short[] mIndices;
    protected static float[] mUV;
    protected static float[] mVertices;
    protected boolean mAmbilight;
    protected float mAspectRatio;
    protected int mFormat;
    public ShortBuffer mIndicesBuffer;
    public FloatBuffer mUVBuffer;
    public FloatBuffer mVerticesBuffer;

    protected double degToRad(double paramDouble) {
        return 3.141592653589793D * paramDouble / 180.0D;
    }

    protected void generateEmpty() {
        float[] arrayOfFloat1 = new float[0];
        short[] arrayOfShort = new short[0];
        float[] arrayOfFloat2 = new float[0];
        mVertices = arrayOfFloat1;
        mIndices = arrayOfShort;
        mUV = arrayOfFloat2;
    }

    protected abstract void generateMono();

    protected abstract void generateOverUnder();

    protected abstract void generateSideBySide();

    public int getIndicesLength() {
        return mIndices.length;
    }
    public short[] getmIndices(){
        return mIndices;
    }

    public int getUvsLength() {
        return mUV.length;
    }

    public int getVerticesLength() {
        return mVertices.length;
    }

    protected void initBuffers() {
        ByteBuffer bb = ByteBuffer.allocateDirect(4 * mVertices.length);
        bb.order(ByteOrder.nativeOrder());
        this.mVerticesBuffer = bb.asFloatBuffer();
        this.mVerticesBuffer.put(mVertices);
        this.mVerticesBuffer.position(0);
        ByteBuffer localByteBuffer2 = ByteBuffer.allocateDirect(2 * mIndices.length);
        localByteBuffer2.order(ByteOrder.nativeOrder());
        this.mIndicesBuffer = localByteBuffer2.asShortBuffer();
        this.mIndicesBuffer.put(mIndices);
        this.mIndicesBuffer.position(0);

        ByteBuffer localByteBuffer3 = ByteBuffer.allocateDirect(4 * mUV.length);
        localByteBuffer3.order(ByteOrder.nativeOrder());
        this.mUVBuffer = localByteBuffer3.asFloatBuffer();
        this.mUVBuffer.put(mUV);
        this.mUVBuffer.position(0);

    }

    public boolean isStereoscopic() {
        return this.mFormat > 0;
    }

    protected void setupProjection(int paramInt) {
        this.mFormat = paramInt;
        switch (paramInt) {
            case 1:
                generateSideBySide();
                break;
            case 2:
                generateOverUnder();
                break;
            default:
                generateMono();
        }
        initBuffers();
    }
}
